package com.example.zhinongbao.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Switch;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.zhinongbao.R;


public class AddNewLocalActivity extends AppCompatActivity {
    private ImageButton Back ;
    private EditText NewName , NewPhone , NewLocal ;
    private Switch SetDefault;
    private Button SaveLocal ;

    private String SwitchChange ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_new_local);
        Back = findViewById(R.id.add_new_local_back) ;
        NewName = findViewById(R.id.local_manager_new_name) ;
        NewPhone = findViewById(R.id.local_manager_new_phone) ;
        NewLocal = findViewById(R.id.local_manager_new_local) ;
        SetDefault = findViewById(R.id.set_default_local) ;
        SaveLocal = findViewById(R.id.save_local_btn);
        Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        SetDefault.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    SwitchChange = "是";
                }else {
                    SwitchChange = "否";
                }
            }
        });
        SaveLocal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = NewName.getText().toString();
                String phone = NewPhone.getText().toString();
                String local = NewLocal.getText().toString() ;
                Toast.makeText(AddNewLocalActivity.this, "添加信息：姓名："+name + "&电话："
                        +phone+"&地址："+local+"&默认地址："+SwitchChange, Toast.LENGTH_SHORT).show();
                onBackPressed();
            }
        });
    }
}
